// ============================== 导入依赖 ============================== //

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async remoteOne({ state: { API, one, MAP } }) {
    const obj = await API.getOne(one, API.transTip(MAP.tipOne))
    let [device, video] = [{}, {}]
    if (one.actionDeviceId) device = await API.getIOT({ id: one.actionDeviceId }, API.transTip('查询联动设备名称'))
    if (one.actionVideoDeviceId) video = await API.getIOT({ id: one.actionVideoDeviceId }, API.transTip('查询联动视频名称'))
    return transOne(obj, device, video)
  },
}

// ============================== 转换方法 ============================== //

const transOne = (obj, device, video) => {
  const action = []
  if (obj.actionDevice === 1) action.push(1)
  if (obj.actionVideoPop === 1) action.push(2)
  if (obj.actionSms === 1) action.push(3)

  return {
    ...obj,
    action,
    actionDeviceCategory: device.deviceCategoryId,
    actionDeviceType: device.deviceTypeId,
    actionDeviceArea: device.areaId,
    actionDeviceName: device.deviceName,
    actionVideoDeviceName: video.deviceName,
  }
}
